package com.tyun.common.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CachingConfigurationSelector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author taocongcong
 * @create 2017-07-07 14:27
 */
@Configuration
public class JedisCache extends CachingConfigurationSelector {

    private static final Logger LOGGER= LoggerFactory.getLogger(JedisCache.class);

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;

    @Bean(name="jedisPool")
    public JedisPool jedisPool() {
        LOGGER.info("JedisPool注入成功！！");
        LOGGER.info("redis地址：" + host + ":" + port);
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host , port);
        return jedisPool;
    }
}
